package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	
	private static final String driver="oracle.jdbc.driver.OracleDriver";
	
	private static final String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
	//"jdbc:oracle:thin:@127.0.0.1:1521:ORCL"
	private static final String user="carl";
	private static final String password="123";
	
	public static Connection getConnection(){
		
		Connection connection = null;
		
		try {
			
			Class.forName(driver);
			connection = DriverManager.getConnection(url, user, password);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 		
		return connection;
	}
	
	public static void release(Connection conn,PreparedStatement ps, ResultSet rs){
		
		try {
			if(rs!=null){
				rs.close();
			}
			if(ps!=null){
				ps.close();
			}
			if(conn!=null){
				conn.close();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static void main(String[] args) {
		
		Connection conn = getConnection();
		System.out.println(conn);
//		release(conn, ps, rs);
	}
	

}
